// import request from '/@/utils/request.js'
import { httpReqeustApi } from '/@/api/linxyun/base/index.ts'
import lxy_event from './lxy_page_event'
const httpRequest = httpReqeustApi()

class Lxy_page_event_cpn extends lxy_event {
	// _domain = "";    //远程服务域名;
	// _uri = "";       //远程服务URI;
	cfg
	constructor(e) {
		super(e)
		this.init(e)
	}

	init(e) {
		this.cfg = e
	}

	async callEvent(expParams, rowIndex = -1) {
		console.log('[Debug][CpnEvent]callEvent: cfg: ', this.cfg)
		const inputParams = this.calcInputParams(rowIndex)
		if (inputParams === undefined || inputParams === Number.NaN) {
			return null
		}
		const { interfaceName, outputParams } = this.cfg
		const op = {}
		let outputParamsKeys
		const theInputParams = { ...inputParams }
		if (outputParams) {
			outputParamsKeys = Object.keys(outputParams)

			if (outputParamsKeys.length > 0) {
				outputParams.map((o) => {
					op[o.pName] = o.pValue
				})
				console.log('op.label', op)
				if (op.label) {
					theInputParams[op.label] = expParams
				}
			}
		}

		const requestRes = await httpRequest.SyncPost(interfaceName, null, theInputParams)
		// const requestRes = await request({
		// 	url: interfaceName,
		// 	method: 'post',
		// 	params: theInputParams
		// })
		console.log(requestRes)
		const opKeys = Object.keys(op)
		if (opKeys.length) {
			return requestRes.Records.map((d) => {
				const res = {}
				opKeys.map((k) => {
					res[k] = d[op[k]]
				})
				return res
			})
		} else {
			return requestRes.Records
		}
	}
}

export default Lxy_page_event_cpn
